home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Graphics / Pan / pan.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1980-01-15  |  8.7 KB  |  361 lines

  1. /* Pan.rexx ver .2 27 April 2001 */
  2. /* This script pans a large image, building frames for video usage.*/
  3. /* First, see if PPaint is running */
  4. /* trace results */
  5.  
  6. PPPORT = 'PPAINT'
  7.  
  8. IF ~SHOW('p', PPPORT) then do
  9.     if exists('PPaint:PPaint') then do
  10.        Address command 'Run >NIL: PPaint:PPaint'
  11.        DO 30 while ~show('p',PPPORT)
  12.             address command 'Wait >NIL: 1 sec'
  13.        END
  14.     end
  15.     else do
  16.         Say "Personal Paint could not be loaded."
  17.         Exit 10
  18.     end
  19. end
  20.  
  21. if ~show('p', PPPORT) then do
  22.     say 'Personal Paint Rexx port could not be opened'
  23.     exit 10
  24. end
  25. address value PPPORT
  26. Options results
  27. options failat 10000
  28.  
  29. /* Identify sourcefile & set up buffers */
  30.  
  31. say 'What is your sourcefile?'
  32. pull SourceFile
  33.  
  34. say 'What is your destination directory'
  35. pull DestPath
  36.  
  37. /* say 'What is your destination image size?' */
  38. /* pull DestX DestY */
  39.  
  40. /* Hard coded until we figure out how to force it! */
  41.  
  42. DestX = 640
  43. DestY = 464
  44.  
  45. GetFileFormat 'FILE' Sourcefile 'FULL'
  46.  
  47. String = Result
  48.  
  49.   Error = RC
  50.   Call ErrorCode()
  51.  
  52. ImageType = word(String,1)
  53. ImageWidth = word(String,2)
  54. ImageHeight = word(String,3)
  55. ImageColors = word(String,4)
  56.  
  57. /* Convert number of colors to bitplanes */
  58.  
  59. If ImageColors =16777216
  60.   then ColorSize = 24
  61.   else NOP
  62. If ImageColors = 256
  63.   then ColorSize = 8
  64.   else NOP
  65. If ImageColors = 128
  66.   then ColorSize = 7
  67.   else NOP
  68. If ImageColors = 64
  69.   then ColorSize = 6
  70.   else NOP
  71. If ImageColors = 32
  72.   then ColorSize = 5
  73.   else NOP
  74. If ImageColors = 16
  75.   then ColorSize = 4
  76.   else NOP
  77. If ImageColors = 8
  78.   then Colorsize = 3
  79.   else NOP
  80. If ImageColors = 4
  81.   then Colorsize = 2
  82.   else NOP
  83. If ImageColors = 2
  84.   then ColorSize = 1
  85.   else NOP
  86.  
  87. /* See if the destination image is too big */
  88.  
  89. If DestX > ImageWidth then do
  90.    say 'Destination wider than source. Aborted'
  91.    Say 'ImageWidth is' ImageWidth 'Destination is' DestX
  92.    Exit
  93.    end
  94.    else If DestY > ImageHeight then do
  95.       say 'Destination taller than source. ABorted.'
  96.       say 'ImageHeight is' ImageHeight 'Destination is' DestY
  97.       Exit
  98.       end
  99.       else NOP
  100.  
  101. Say 'What is the starting center point for the pan (x/y)?'
  102. pull StartX StartY
  103.  
  104. If ( StartX - DestX/2 ) < 0 then do
  105.    Say 'X starting point places you outside the image. Aborted.'
  106.    Exit
  107.    end
  108.    else If ( StartY - DestY/2 ) < 0 then do
  109.       Say 'Y starting point places you outside the image. Aborted.'
  110.       Exit
  111.       End
  112.       else NOP
  113.  
  114. Say 'What is the ending center point for the pan (x/y)?'
  115. pull EndX EndY
  116.  
  117. If EndX + (DestX/2) > ImageWidth then do
  118.    say 'X ending point places you outside the image. Aborted.'
  119.    Exit
  120.    End
  121.    else If EndY + (DestY/2) > ImageHeight then do
  122.       Say 'Y ending point places you outside the image. Aborted.'
  123.       Exit
  124.       End
  125.       else NOP 
  126.  
  127. Say 'How many frames in this video sequence?'
  128. Pull Frames
  129. Error = RC
  130. Call ErrorCode()
  131.  
  132. Set 'FORCE "SCREENW=640" "SCREENH=464" "Colors=256"'
  133. Error = RC
  134. Call ErrorCode()
  135.  
  136. LoadBrush 'FILE' SourceFile
  137. Error = RC
  138. Call ErrorCode()
  139.  
  140. UseBrushPalette
  141. Error = RC
  142. Call ErrorCode()
  143.  
  144. SetBrushHandle 'OffsetX' 0 'OffsetY' 0
  145. Error = RC
  146. Call ErrorCode()
  147.  
  148. ClearImage
  149. Error = RC
  150. Call ErrorCode()
  151.  
  152. /* Now pan through the bitmap */
  153. BrushX = StartX - 320
  154. BrushY = StartY - 232
  155. k = 1
  156. /* First, handle the case of a horizontal pan */
  157.  
  158. If StartY = EndY then do
  159.    DeltaX = (EndX - StartX)/Frames
  160.    do i for Frames
  161.       ClearImage
  162.       Error = RC
  163.       Call ErrorCode()
  164.       SetBrushHandle 'OffsetX' BrushX 'OffsetY' BrushY
  165.       Error = RC
  166.       Call ErrorCode()
  167.       PutBrush 'X' 0 'Y' 0
  168.       Error = RC
  169.       Call ErrorCode()
  170.       Temp = BrushX + DeltaX
  171.       BrushX = Trunc(Temp,0)
  172.       Call SaveFile()
  173.       End
  174.    End
  175.  
  176. /* Next, address the case of a vertical pan */
  177.  
  178.    Else If StartX = EndX then do
  179.       DeltaY = (EndY-StartY)/Frames
  180.       do i for Frames
  181.          ClearImage
  182.          Error = RC
  183.          CAll ErrorCode()
  184.          SetBrushHandle 'OffsetX' BrushX 'OffsetY' BrushY
  185.          Error = RC
  186.          Call ErrorCode()
  187.          PutBrush 'X' 0 'Y' 0
  188.          Temp = (BrushY + DeltaY)
  189.          BrushY = Trunc(Temp,0)
  190.          Call SaveFile()
  191.          End
  192.       End
  193.  
  194. /* Finally, handle the case where the pan follows an angle */
  195.  
  196.          Else do
  197.             Slope = (StartY-EndY)/(StartX - EndX)
  198.             DeltaX = (EndX - StartX)/Frames
  199.             XIncr = 0
  200.             do i for Frames
  201.                Clear Image
  202.                Error = RC
  203.                Call ErrorCode()
  204.                SetBrushHandle 'OffsetX' BrushX 'OffsetY' BrushY
  205.                Error = RC
  206.                Call ErrorCode()
  207.                PutBrush 'X' 0 'Y' 0
  208.                Error = RC
  209.                Call ErrorCode()
  210.                Temp = XIncr + DeltaX +.5
  211.                XIncr = Trunc(Temp,0)
  212.                YIncr = XIncr * Slope
  213.                Temp = BrushY + YIncr
  214.                BrushY = Temp
  215.                Temp = BrushX + XIncr
  216.                BrushX = Temp
  217.                Call SaveFile()
  218.                End
  219.          End
  220. Exit
  221.  
  222. /* End of Main Program. The supporting players follow */
  223.  
  224. */ SaveFile writes the current image to a picxxxx file in the path */
  225. SaveFile: M = DestPath||'/pic0'
  226.   j = k
  227. /* Handle 100's digit */
  228.   j1 = Trunc(j/100,0)
  229.   Call Digit()
  230.   if J > 99 then do
  231.     temp = J-trunc(j/100,0)*100
  232.     J = temp
  233.     end
  234.     else NOP
  235. /* Handle 10's digit */
  236.   j1 = Trunc(j/10,0)
  237.   Call Digit()
  238.   if J > 9 then do
  239.     temp = J-trunc(j/10,0)*10
  240.     j = temp
  241.     end
  242.     else NOP
  243. /* Handle 1's digit */
  244.   j1 = Trunc(J,0)
  245.   Call Digit()
  246.   temp = k + 1
  247.   k = temp
  248. /* Tacile Feedback for the human watching */
  249.   Say M
  250.   SaveImage 'File' M
  251.   Error = RC
  252.   Call ErrorCode()
  253. Return
  254.  
  255. /*Digit adds each digit to the end of the file name */
  256.  
  257. Digit: If J1 = 1 then M1 = M||'1'
  258.     else if J1 = 2 then M1 = M||'2'
  259.       else if J1 = 3 then M1 = M||'3'
  260.         else if J1 = 4 then M1 = M||'4'
  261.           else if J1 = 5 then M1 = M||'5'
  262.             else if J1 = 6 then M1 = M||'6'
  263.               else if J1 = 7 then M1 = M||'7'
  264.                 else if J1 = 8 then M1 = M||'8'
  265.                   else if J1 = 9 then M1 = M||'9'
  266.                     else M1 = M||'0'
  267. M = M1
  268. Return
  269.  
  270. /* Error Code types out the error message associated with any error code */
  271. /* This routine is always called whenever anything of significance is done*/
  272. /* By an AREXX call to PPaint. Errors in the program you are reading are */
  273. /* assumed to have been caught, and are not trapped - trapping is */
  274. /* By the host AREXX environment */
  275.  
  276. /* All defined PPaint AREXX error codes are trapped, even though it may */
  277. /* Very unlikely some of these situations could occur as the program is */
  278. /* being used here                                                      */
  279.  
  280.  
  281.  
  282. Errorcode: If Error > 0 then do
  283.   If error = 1 then msg='Program not found'
  284.   else nop
  285.   If error = 2 then msg='Execution halted'
  286.   else nop
  287.   If error = 3 then msg='Insufficient memory'
  288.   else nop
  289.   If error = 4 then msg='Invalid character'
  290.   else nop
  291.   If Error = 5 then msg='Operation cancelled by user'
  292.   else nop
  293.   If Error = 30 then msg='Unknown command'
  294.   else nop
  295.   If error = 31 then msg='required argument missing'
  296.   else nop
  297.   If error = 32 then msg='Too many arguments'
  298.   else nop
  299.   If error = 33 then msg='Incompatible options'
  300.   else nop
  301.   If error = 34 then msg='Generic error'
  302.   else nop
  303.   If error = 35 then msg='Error during file I/O'
  304.   else nop
  305.   If error = 36 then msg='File could not be opened'
  306.   else nop
  307.   If error = 37 then msg='Not enough memory'
  308.   else nop
  309.   If error = 38 then msg='File format not recognized'
  310.   else nop
  311.   If error = 39 then msg='File does not contain the required data.'
  312.   else nop
  313.   If error = 40 then msg='Error in file data'
  314.   else nop
  315.   If error = 41 then msg='Unable to load this type of image'
  316.   else nop
  317.   If error = 42 then msg='Decryption impossible'
  318.   else nop
  319.   If error = 43 then msg='Warning:partial load'
  320.   else nop
  321.   If error = 44 then msg='Printer device cannot be opened'
  322.   else nop
  323.   If error = 45 then msg='Error during printer output'
  324.   else nop
  325.   If error = 46 then msg='Unknown format'
  326.   else nop
  327.   If error = 47 then msg='Unknown format option'
  328.   else nop
  329.   If error = 48 then msg='Unknown setting'
  330.   else nop
  331.   If error = 49 then msg='Numerical argument required'
  332.   else nop
  333.   If error = 50 then msg='Value out of range/illegal value'
  334.   else nop
  335.   If error = 51 then msg='no animation to work on'
  336.   else nop
  337.   If error = 52 then msg='Unknown image processing filter'
  338.   else nop
  339.   If error = 53 then msg='User brush needed'
  340.   else nop
  341.   If error = 54 then msg='Anim brush needed'
  342.   else nop
  343.   If error = 55 then msg='The command cannot process anim-brushes'
  344.   else nop
  345.   If error = 56 then msg='Font could not be opened'
  346.   else nop
  347.   If error = 57 then msg='No unused brushes available'
  348.   else nop
  349.   If error = 58 then msg='No undo/redo available'
  350.   else nop
  351.   If error = 59 then msg='Unknown or unsupported video mode'
  352.   else nop
  353.   say msg
  354.   End
  355. else nop
  356.   Return
  357.  
  358. /* That's All, Folks! */
  359.  
  360. Exit
  361.